<?php

/**
 * specialEvent actions.
 *
 * @package    ldaad
 * @subpackage specialEvent
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class specialEventActions extends autospecialEventActions
{

  public function executeBackToConference()
  {
    $specialEvent = SpecialEventPeer::retrieveByPK($this->getRequestParameter('id'));
    $this->redirect('conference/edit?id='.$specialEvent->getConferenceId());
  }
  
  public function executeBackToConferenceList()
  {
    $this->redirect('conference/list');
  }
  
  public function executeDeleteToConference()
  {

    $specialEvent = SpecialEventPeer::retrieveByPK($this->getRequestParameter('id'));
    
    $this->forward404Unless($specialEvent);
    
    $tempConferenceId = $specialEvent->getConferenceId();
    
    $specialEvent->delete();
    
    $this->redirect('conference/edit?id='.$tempConferenceId);
    
  }

//public registration

  public function executeAvailableSpecialEvents()
  {
    /*
    Step to list available specialevents which correspond to  selected conference
    1. Get conference Id from user session
    2. create criteria
    3. get special event from database 
    4. put 3. into $this
    */
    $conferenceID = $this->getUser()->getAttribute('conferenceIDSession');

    $c = new Criteria();
    $c-> add(SpecialEventPeer::CONFERENCE_ID, $conferenceID);
    $this->special_events = SpecialEventPeer::doSelect($c);
    
    //preventive-validation to ensure overlapped session will not be register-able
    $forbiddenIDArray = array ();
    
    if ($this->getUser()->hasAttribute('specialEventIDArraySession'))
    {
      $specialEventIDArray = $this->getUser()->getAttribute('specialEventIDArraySession');
      
      $forbiddenIDArray = SpecialEvent::getClashedSpecialEventIDs($specialEventIDArray);
      
      $this->getUser()->setAttribute('forbiddenSpecialEventIDArraySession' , $forbiddenIDArray);
    }
    
    
    
  }
  
  public function executeRegisterIndividualSpecialEvent()
  {
    //CFR put specialevent id in an array... easier
    /*
    Step to register individual special event
    1. get specialevent id from request parameter
    2. put specialeventid in user session
    3. redirect to specialEvent/availableSpecialEvents
    */
    $registeredSpecialEventID = $this->getRequestParameter('id');
    
    $this->getUser()->setAttribute('specialEventIDSession'.$registeredSpecialEventID, $registeredSpecialEventID);
    
    if (!$this->getUser()->hasAttribute('specialEventIDArraySession'))
    {
      $registeredSpecialEventIDArray = array ( );
    }
    else
    {
      $registeredSpecialEventIDArray = $this->getUser()->getAttribute('specialEventIDArraySession');
    }
    
    $registeredSpecialEventIDArray[] = $registeredSpecialEventID;

    $this->getUser()->setAttribute('specialEventIDArraySession', $registeredSpecialEventIDArray);

    return $this->redirect('specialEvent/availableSpecialEvents');
  }
  

  
  public function executeDeregisterIndividualSpecialEvent()
  {
    /*
    Step to deregister individual special event
    1. get specialevent id from request parameter
    2. remove specialeventid in user session
    3. redirect to specialEvent/availableSpecialEvents
    */
    $deregisteredSpecialEventID = $this->getRequestParameter('id');

    $this->getUser()->getAttributeHolder()->remove('specialEventIDSession'.$deregisteredSpecialEventID);
    
    $registeredSpecialEventIDArray = $this->getUser()->getAttribute('specialEventIDArraySession');

    $registeredSpecialEventIDArray = myTools::array_remove_value($registeredSpecialEventIDArray, $deregisteredSpecialEventID);
    
    $this->getUser()->setAttribute('specialEventIDArraySession', $registeredSpecialEventIDArray);

    return $this->redirect('specialEvent/availableSpecialEvents');
  }

  public function executeConfirmedSpecialEvents()
  {
    return $this->redirect('publicRegistration/consolidateRegistration');  
  }  
  
}
